#ifndef IMPORTSTUDYMODEL_H
#define IMPORTSTUDYMODEL_H

#include <QAbstractTableModel>
#include <QDateTime>

typedef struct ImageRecord
{
    QString studyIUid;
    QString seriesIUid;
    QString imageIUid;
    QString imageCUid;
    bool ok;
    QString file;
    ImageRecord():ok(false){}
}ImageRecord;

typedef struct StudyRecord
{
    QString studyIUid;
    QString accNumber;
    QString patientId;
    QString patientName;
    QString patientSex;
    QDate patientBirth;
    QString patientAge;
    QString admissionId;
    QString medicalAlerts;
    QDateTime studyTime;
    QString modality;
    QString studyDesc;
    QString institution;
    QString bodyPart;
    QString status;
    QList<ImageRecord*> imageList;
    ~StudyRecord(){qDeleteAll(imageList);}
}StudyRecord;

class ImportStudyModel : public QAbstractTableModel
{
    Q_OBJECT
public:
    enum ColumnType {
        AccNumber,
        PatientId,
        PatientName,
        PatientSex,
        PatientBirth,
        PatientAge,

        StudyTime,
        Modality,
        Institution,

        Images,
        ImportedImages,
        StudyStatus,

        ColumnCount,
    };

    explicit ImportStudyModel(QObject *parent = 0);
    ~ImportStudyModel();

    int rowCount(const QModelIndex &parent = QModelIndex()) const;
    int columnCount(const QModelIndex &/*parent*/) const { return ColumnCount; }
    QModelIndex parent(const QModelIndex &/*child*/) const { return QModelIndex(); }
    QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
    QVariant headerData(int section, Qt::Orientation orientation, int role) const;
    bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());

    QList<StudyRecord*> getStudyList() const { return studyList; }
    int getStudyCnt() const { return studyList.size(); }
    int getImageCnt() const;

public slots:
    void appendStudy(StudyRecord *study);
    void updateStudyStatus(StudyRecord *study);
    void clear();

private:
    QList<StudyRecord*> studyList;
};

#endif // IMPORTSTUDYMODEL_H
